package com.example.frn.controller;

import cn.hutool.core.bean.BeanUtil;
import com.example.frn.dto.*;
import com.example.frn.entity.Film;
import com.example.frn.entity.Maker;
import com.example.frn.service.FilmService;
import com.example.frn.service.MakerService;
import com.example.frn.vo.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/v1/film")
public class FilmController {
    @Autowired
    private FilmService filmService;
    @PostMapping("save")
    public R save(@RequestBody FilmInsertDto dto){
//        Film film = BeanUtil.copyProperties(dto, Film.class);
        if(filmService.save(dto))
            return R.ok(true);
        else return R.error(false);
    }
    @PostMapping("update")
    public R update(@RequestBody FilmUpdateDto dto){
        //Film film = BeanUtil.copyProperties(dto, Film.class);
        if(filmService.updateById(dto))
            return R.ok(true);
        else return R.error(false);
    }
    @PostMapping("remove/{id}")
    public R remove(@PathVariable("id") Integer id){
        if(filmService.removeById(id))
            return R.ok(true);
        else return R.error(false);
    }
    @GetMapping("detail/{id}")
    public R detail(@PathVariable("id") Integer id){
        return R.ok(filmService.getById(id));
    }
    @PostMapping("page")
    public R page(@RequestBody MakerPageDto dto){
        return R.ok(filmService.page(dto.getPageNum(),dto.getPageSize(),dto.getName(),dto.getCid()));
    }
}
